package com.zzc.emotisenseclassroom.domain.user.service.impl;

import com.zzc.emotisenseclassroom.dbservice.user.UserDbService;
import com.zzc.emotisenseclassroom.domain.user.service.UserService;
import com.zzc.emotisenseclassroom.domain.user.utils.UserUtils;
import com.zzc.emotisenseclassroom.dto.user.UserDTO;
import com.zzc.emotisenseclassroom.pojo.UserLogin;
import com.zzc.emotisenseclassroom.pojo.UserRegister;
import com.zzc.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Copyright Zzc
 * FileName: UserServiceImpl
 * Author:   Zzc
 * Date:     2024/4/1815:19
 * Description:用户业务层实现类
 * hISTORY:
 * <author>  <time>     <version>    <desc>
 * 作者姓名   修改时间       版本号       描述
 * Zzc                   1.0.0
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDbService userDbService;


    @Override
    public UserDTO login(UserLogin userLogin) {
      return userDbService.getUserInfo(userLogin);
    }

    @Override
    public UserDTO register(UserRegister userRegister){
        Long accountNumber = userDbService.checkAccountNumberIsExists(Long.valueOf(userRegister.getAccountNumber()));
        if (accountNumber != null){
            return null;
        }

        userDbService.userRegister(userRegister);

        return BeanUtil.convertObj(userRegister, UserDTO.class);
    }

    @Override
    public UserDTO updateUserInfo(UserDTO userDTO) {
        UserUtils.checkUserInfo(userDTO);

        userDbService.updateUserInfo(userDTO);

        return userDTO;
    }

}
